package gui;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;

import javax.swing.JTextPane;
import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.ListModel;

import model.basics.Instructor;
import model.basics.Request;
import org.jdesktop.application.Application;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class SelectInstructorWind extends javax.swing.JPanel {
	
	private model.search.System sistem;
	private Request request;
	private JScrollPane jScrollPane1;
	private JSeparator jSeparator1;
	private JLabel jLabel1;
	private JButton cancelButton;
	private JButton okButton;
	private JList instructorsList;
	private JFrame frame;
	private JTextPane instructorPane;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
//		JFrame frame = new JFrame();
//		frame.getContentPane().add(new SelectInstructorWind());
//		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
//		frame.pack();
//		frame.setVisible(true);
	}
	
	public SelectInstructorWind() {
		super();
		initGUI();
	}
	public SelectInstructorWind(model.search.System sis, Request re, JTextPane ip) {
		super();
		this.sistem = sis;
		this.request = re;
		this.instructorPane = ip;
		frame = new JFrame();
		frame.getContentPane().add(this);
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
		this.setVisible(true);
		initGUI();
	}
	
	private void initGUI() {
		try {
			this.setPreferredSize(new java.awt.Dimension(189, 299));
			frame.setPreferredSize(new java.awt.Dimension(203, 315));
			this.setSize(new java.awt.Dimension(148, 300));
			frame.setSize(203, 315);

			frame.setLocationRelativeTo(null);
			this.setLayout(null);
			{
				jScrollPane1 = new JScrollPane();
				this.add(jScrollPane1);
				jScrollPane1.setBounds(42, 65, 119, 150);
				{
					ListModel instructorsListModel = 
						new DefaultComboBoxModel(new String[] {});
					instructorsList = new JList();
					jScrollPane1.setViewportView(instructorsList);
					instructorsList.setModel(instructorsListModel);
					instructorsList.setBounds(131, 129, 129, 147);
					instructorsList.setPreferredSize(new java.awt.Dimension(112, 147));
					instructorsList.setListData(sistem.getInstructorsList());
				}
			}
			{
				okButton = new JButton();
				this.add(okButton);
				okButton.setBounds(22, 242, 73, 21);
				okButton.setName("okButton");
				okButton.addActionListener(new AddInstructor());
			}
			{
				cancelButton = new JButton();
				this.add(cancelButton);
				cancelButton.setBounds(111, 242, 73, 21);
				cancelButton.setName("cancelButton");
				cancelButton.addActionListener(new Cancel());
			}
			{
				jLabel1 = new JLabel();
				this.add(jLabel1);
				jLabel1.setBounds(5, 12, 178, 31);
				jLabel1.setName("jLabel1");
			}
			{
				jSeparator1 = new JSeparator();
				this.add(jSeparator1);
				jSeparator1.setBounds(42, 55, 119, 10);
			}
			Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public class AddInstructor implements ActionListener{

		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			request.setInstructor((Instructor) instructorsList.getSelectedValue());
			instructorPane.setText(((Instructor)instructorsList.getSelectedValue()).toStrings());
			frame.dispose();
			
		}
		
	}
	
	private class Cancel implements ActionListener{

		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			frame.dispose();
		}
		
	}
	
}
